package com.cheung.leetcode.dp;

import org.junit.jupiter.api.Test;

public class Code746Test {

    public int minCostClimbingStairs(int[] cost) {
        // 第i阶可以是第i-2阶+cost[i-2]和第i-1阶+cost[i-1]
        int[] dp = new int[cost.length + 1];
        for (int i = 2; i <= cost.length; i++) {
            dp[i] = Math.min(dp[i - 2] + cost[i - 2], dp[i - 1] + cost[i - 1]);
        }
        return dp[cost.length];
    }

    @Test
    public void test1() {
        int[] cost = {10, 15, 20};
        assert minCostClimbingStairs(cost) == 15;
    }

    @Test
    public void test2() {
        int[] cost = {1, 100, 1, 1, 1, 100, 1, 1, 100, 1};
        assert minCostClimbingStairs(cost) == 6;
    }
}
